//
//  ByViewStoreTimeConsume.m
//  mijifen_ios
//
//  Created by mc on 2017/10/31.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewStoreTimeConsume.h"
// cell
#import "ByCellStoreConsume.h"
@interface ByViewStoreTimeConsume()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *placeArray;

@end

@implementation ByViewStoreTimeConsume
- (void)setupUI{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = BY_TABLE_COLOR;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self addSubview:self.tableView];
}

- (void)setFrame:(CGRect)frame{
    [super setFrame:frame];
    self.tableView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
}

#pragma mark - getter
- (NSArray *)placeArray{
    if (!_placeArray) {
        _placeArray = @[@"请输入会员手机号",@"本次扣除次数：",@"剩余次数："];
    }
    return _placeArray;
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.placeArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        ByCellStoreConsume *cell = [ByCellStoreConsume cellWithTableView:tableView andPlaceStr:self.placeArray[indexPath.section] andDeduct:@""];
        return cell;
    }else{
        static NSString *indentier = @"cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:indentier];
            cell.textLabel.font = FONT(16);
            cell.detailTextLabel.font = FONT(16);
            cell.backgroundColor = [UIColor whiteColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

        }
        cell.textLabel.text = self.placeArray[indexPath.section];
        cell.detailTextLabel.text = @"1次";
        return cell;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 0) {
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)];
        UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, SCREEN_WIDTH - 20, 20)];
        [footerView addSubview:footerLabel];
        footerView.backgroundColor = [UIColor clearColor];
        footerLabel.font = FONT(16);
        // 测试数据
        footerLabel.text = @"余额：200";
        return footerView;
    }
    return [UIView new];

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return 35;
    }
    return 0.0001;
}

@end
